package day02;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/2 14:31
 * 杨辉三角形
 */

public class YangHuiTriangle {
    private static int element(int i, int j) {
        if (j == 0 || j == i) {
            return 1;
        }
        return element(i - 1, j - 1) + element(i - 1, j);
    }

    public static void printSpace(int n) {
        for (int i = 0; i < n; i++) {
            System.out.print(" ");
        }
    }

    public static void print(int n) {
        for (int i = 0; i < n; i++) {
            printSpace((n - 1 - i) * 2);
            for (int j = 0; j <= i; j++) {
                System.out.printf("%-4d", element(i, j));
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        // System.out.println(element(4, 2));
        print(5);
    }
}
